<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%
    String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="<%=path %>/view/js/jquery-2.1.4.min.js"></script>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
手机号码：<input id="phone" name="phone" type="text" value="${userInfo.phone}" readonly="readonly"/><br>
用户名： ${userInfo.userName}<br>
用户性别： ${userInfo.userGender} <br>
身份证号：  ${userInfo.idNumber}<br>
运营商：  ${userInfo.operatorName}<br>
归属地：${userInfo.provName}${userInfo.cityName} <br>
服务密码：<input id="password" name="password" type="text" value="${userInfo.password}"/>  <br>
收货地址：<input id="userAddress" name="userAddress" type="text" value="${userInfo.userAddress}"/>  <br>
<input id="update" name="update" type="button"  value="更新"/> 


<script type="text/javascript">  
    $(document).ready(function(){  
         $("#update").click(function(){  
        	 var phone = $.trim($("#phone").val());
        	var userAddress = $.trim($("#userAddress").val());
        	var password = $.trim($("#password").val());
        	var actionUrl= "<%=path%>/userController/updateMyInfo.do";
        	 
        	 if(!checkInfo()){
 				return;
 			}
        	
            $.ajax({  
                url:actionUrl,  
                type:"post",  
                data:JSON.stringify({phone:phone,
                	password:password,
                	userAddress:userAddress}), 
                
			    dataType : "JSON",
			    cache:false,
			    contentType:"application/json",
                success:function(data){  
                	if(data.flag == true){
                		alert("修改成功");
                		 window.location.href = "<%=path%>/indexController/index.do";
						
					}else if(data.flag == false){
						 alert("修改失败！");
					} else {
						        alert("修改失败！");
						    		
					} 
                }  
            });  
              
             
              
        });    
       });  
    
    
  //基本信息校验
	function checkInfo(){
		var userAddress = $.trim($("#userAddress").val());
    	var password = $.trim($("#password").val());
		
		
		if(password == ""){
			alert("密码不能为空");
			
			$("#password").focus();
			return false;
		}
		
		
		
		if(userAddress == ""){
			alert("收货地址不能为空");
			$("#userAddress").focus();
			return false;
		}
		
		return true;
		
	}
	
    
</script>  
</body>
</html>